package cn.wolfcode.web.controller;

import cn.wolfcode.domain.Permission;
import cn.wolfcode.qo.JsonResult;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IDepartmentService;
import cn.wolfcode.service.IPermissionService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    private IPermissionService permissionService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo ){
        PageInfo<Permission> result  = permissionService.query(qo);
        model.addAttribute("result",result);

        return "permission/list";
    }
    @RequestMapping("/delete")
    public String delete(Long id ){
        if (id!=null){
            permissionService.delete(id);
        }
        return "redirect:/permission/list.do";
    }
    @RequestMapping("/input")
    public String input(Long id,Model model){
        if (id!=null){
            Permission permission = permissionService.select(id);
            model.addAttribute("permission",permission);

        }
        return "permission/input";
    }

    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(Permission permission){
        if (permission.getId()!=null){
            permissionService.update(permission);
        }
        permissionService.insert(permission);
        return "redirect:/permission/list.do";
    }
   /* @RequestMapping("/reload")
    public JsonResult reload( ){
        try {
            permissionService.reload();
            return new JsonResult(true,"yes");
        }catch (Exception e){
            e.printStackTrace();
        }
       return  new JsonResult(false,"no");

    }*/

}
